#ifndef GAMEROLE_H__
#define GAMEROLE_H__

//include header
#include <covariant>

//using namespace
using namespace std;


namespace npMemento
{
    //class forward declaration
    class Memento;

    class GameRole ://  public BaseClass
        public covariant
    {
        //friend
        
        //embedded type
        
        //class skeleton
        public: GameRole();
        public: GameRole(const GameRole& cpy);
        public: GameRole(GameRole&& mov) noexcept;
        public: virtual ~GameRole();
        public: GameRole& operator=(const GameRole& asn);
        public: GameRole& operator=(GameRole&& mva) noexcept;
        public: virtual shared_ptr<covariant> clone() const throw();
        public: virtual shared_ptr<covariant> steal(void* sft=nullptr) throw();

        //other constructors
        
        //public methods
        public: shared_ptr<Memento> saveAsMemo() const throw();
        public: void loadFromMemo(shared_ptr<Memento>&& memo) throw();
        public: void show() const throw();
        public: void attack() throw();

        //protected methods
        
        //private methods
        
        //protected data
        /* 类中不应该存在protected 访问级别的data
         * 要么私有，要么私有而后给出protected 访问级别的methods !!! */
        
        //private data
        /* 类中不应存在指针类型成员，
         * 取而代之，应使用智能指针予以包裹
         * 使用shared_ptr表示类拥有指针指向对象
         * 使用weak_ptr表示类仅可以使用指针指向对象
         * 智能指针对指针成员的封装和使用准则：
         * 1.类对象不允许使用unique_ptr包裹
         * 2.推敲业务逻辑，如果是共享的(share_ptr)，则尽可能少的共享指针对象
         * 3.如果从业务逻辑中发现类仅仅使用某个指针所指对象，则务必使用weak_ptr包裹指针，
         *   以此切实地描述这种使用而不拥有的关系
         * 4.类成员weak_ptr<*> ths，由其产生的，包裹this指针的，shared_ptr只允许在局部使用 */
        private: int vitality;
        private: int attack_;
        private: int defense;
        //static part
        
        //others
    };

    //inline functions
    inline GameRole::GameRole() // : BaseClass()
    {
        this->vitality = 100;
        this->attack_ = 100;
        this->defense = 100;
    }
    
    inline GameRole::GameRole(const GameRole& cpy) // : BaseClass(cpy)
    {
        this->vitality = cpy.vitality;
        this->attack_ = cpy.attack_;
        this->defense = cpy.defense;
    }
    
    inline GameRole::GameRole(GameRole&& mov) noexcept // : BaseClass(move(mov))
    {
        this->vitality = mov.vitality;
        this->attack_ = mov.attack_;
        this->defense = mov.defense;
    }
    
    inline GameRole::~GameRole()
    {
        
    }
    
    inline GameRole& GameRole::operator=(const GameRole& asn)
    {
        if (this == &asn)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(asn);
            
            //To do
            this->vitality = asn.vitality;
            this->attack_ = asn.attack_;
            this->defense = asn.defense;
            
            return *this;
        }
    }
    
    inline GameRole& GameRole::operator=(GameRole&& mva) noexcept
    {
        if (this == &mva)
        {
            return *this;
        }
        else
        {
            // BaseClass::operator=(move(mva));
            
            //To do
            this->vitality = mva.vitality;
            this->attack_ = mva.attack_;
            this->defense = mva.defense;
            
            return *this;
        }
    }
    
    inline shared_ptr<covariant> GameRole::clone() const throw()
    {
        //new an instance if not abstract.
        return shared_ptr<GameRole>(new GameRole(*this));
    }
    
    inline shared_ptr<covariant> GameRole::steal(void* sft) throw()
    {
        GameRole* shf = static_cast<GameRole*>(sft);
        if (this == shf)
        {
            return shared_ptr<covariant>();
        }
        else
        {
            shared_ptr<GameRole> ret;
            if (!shf)
            {
                //new an instance if not abstract.
                ret = shared_ptr<GameRole>(new GameRole(*this));
                shf = ret.get();
            }
            
            // BaseClass::steal(shf);
            
            //To do
            shf->vitality = this->vitality;
            shf->attack_ = this->attack_;
            shf->defense = this->defense;
            
            return ret;
        }
    }
} // namespace npMemento


#endif //GAMEROLE_H__
